package com.design.flyweight;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author cxx
 * @create 2020-04-21 11:13
 **/
public class UserFactory {


    private static Map<String,User> USER_MAP = new ConcurrentHashMap<> ();
    
    public static User getUser(String numId){

        User user = USER_MAP.get (numId);

        if(user != null){
            return user;
        }

        user = USER_MAP.putIfAbsent (numId, new User (numId));
        if(user == null){
           user = USER_MAP.get (numId);
        }
        return user;

    }

}
